package cn.springcloud.alibaba.auth.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.provider.AuthorizationRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@Controller
@SessionAttributes("authorizationRequest")
public class GrantController {

	/**
	 * 自定义确认授权页面
	 */
	@RequestMapping("/oauth/confirm_access")
	public ModelAndView getAccessConfirmation(Map<String, Object> model) {
		log.info("model:{}", model);
		AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");
		ModelAndView view = new ModelAndView();
		view.setViewName("grant"); //自定义页面名字，resources/templates/grant.html
		view.addObject("clientId", authorizationRequest.getClientId());
		view.addObject("scopes", authorizationRequest.getScope());
		return view;
	}
}
